/*
 ------------------------------------------------------------------------------
 Copyright (C) 2009-2011 Eternal Games.

 This file is part of the Eternal Tech source code.

 The Eternal Tech source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Eternal Tech source code is distributed in the hope that it will be useful,
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Eternal Tech source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// cl_local.h - Local header file to all client files
//


#if !defined(__CL_LOCAL_H__) || !INCLUDE_GUARDS
#define __CL_LOCAL_H__


#include "../qcommon/qcommon.h"


// Connection states
enum connectionState_t {
	CS_UNINITIALIZED,							// Only before initialization or for dedicated servers
	CS_DISCONNECTED,							// Not talking to a server
	CS_CONNECTING,								// Sending request packets to the server
	CS_CHALLENGING,								// Sending challenge packets to the server
	CS_CONNECTED,								// Connection established, getting game state
	CS_LOADING,									// Only during level load, never during main loop
	CS_PRIMED,									// Got game state, waiting for first snapshot
	CS_ACTIVE									// Game views should be displayed
};

struct media_t {
	struct material_t		*cinematicMaterial;
	struct material_t		*whiteMaterial;
	struct material_t		*consoleMaterial;
	struct material_t		*charsetMaterial;

	fontSet_t				*genericFont;
};

struct loadingInfo_t {
	char					map[MAX_PATH_LENGTH];
	char					name[MAX_PATH_LENGTH];

	char					string[128];
	int						percent;
};

struct clientActive_t {
	int todo;
};

//extern clientActive_t		cl;

struct clientStatic_t {
	connectionState_t		state;				// Connection status

	media_t					media;				// The client precaches these files during initialization

	// Loading screen information
	bool				loading;
	loadingInfo_t		loadingInfo;

	// Connection information
	char				serverName[128];	// Name of server from original connect
	char				serverMessage[512];	// Connection refused message from server
	netadr_t			serverAddress;		// Address of server from original connect
	int					serverChallenge;	// From the server to use for connecting
	float				connectTime;		// For connection retransmits
	int					connectCount;		// Connection retransmits count
	netchan_t			netChan;

	// Memory pools
	memoryPool_t		*particleMemoryPool;
	memoryPool_t		*consoleMemoryPool;
	memoryPool_t		*locationMemoryPool;
	memoryPool_t		*httpMemoryPool;
	memoryPool_t		*parserMemoryPool;
	memoryPool_t		*keyMemoryPool;
};

extern clientStatic_t		cls;

/*
 ==============================================================================

    CL_PREDICT.CPP

 ==============================================================================
*/

void				CL_BuildSolidList ();

// This function is a bit more upgraded then the old Quake 2 trace function.
// skipNumber is used for all the MASK_* flags and it will skip if used, all flags execpt the one beeing set.
// brushMask are all the MASK_* flags and it is used for tracing bounding boxes.
// If brushOnly i set, it will skip encoding bounding boxes for the inline models.
// entNumber is a index pointer for any entity.
trace_t				CL_Trace (const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int skipNumber, int brushMask, bool brushOnly, int *entNumber);

// This function is a bit more upgraded then the old Quake 2 trace function.
// skipNumber is used for all the MASK_* flags and it will skip if used, all flags execpt the one beeing set.
int					CL_PointContents (const vec3_t point, int skipNumber);

void				CL_CheckPredictionError ();

/*
 ==============================================================================

    CL_PARTICLE.CPP

 ==============================================================================
*/

#define PARTICLES_HASH_SIZE				512

#define MAX_PARTICLE_STAGES				64

struct prtStage_t {
	struct material_t		*material;
	int						time;
	int						count;
	float					color[3];
	float					fadeColor[3];
	float					alpha;
	float					fadeAlpha;
	float					radius;
	float					fadeRadius;
};

struct particleSource_t {
	char					name[MAX_PATH_LENGTH];

	int						numStages;
	prtStage_t				*stages;

	struct prtScript_t		*prtScript;

	particleSource_t		*nextHash;
};

particleSource_t		*CL_FindParticle (const char *name);
particleSource_t		*CL_RegisterParticle (const char *name);

void				CL_ListParticles_f ();

void				CL_InitParticles ();
void				CL_ShutdownParticles ();

/*
 ==============================================================================

    CL_EFFECTS.CPP

 ==============================================================================
*/

enum particleFlags_t {
	PF_NONE				= 0,
	PF_BOUNCE			= BIT(0),
	PF_FRICTION			= BIT(1),
	PF_UNDERWATER		= BIT(3),
	PF_STRETCH			= BIT(3),
	PF_INSTANT			= BIT(4)
};

enum particleType_t {
	PT_GENERIC,
	PT_ROTATE,
	PT_STRETCHED
};

struct particle_t {
	struct material_t		*material;
	int						time;
	int						flags;
	particleType_t			type;

	vec3_t					org;
	vec3_t					vel;
	vec3_t					accel;
	vec3_t					color;
	vec3_t					fadeColor;
	float					alpha;
	float					fadeAlpha;
	float					radius;
	float					fadeRadius;
	float					length;
	float					lengthVel;
	float					rotation;
	float					bounceFactor;

	vec3_t					lastOrg;

	renderPolyVertex_t		vertices[4];

	particle_t				*next;
};

void				CL_AddParticles ();
void				CL_ClearParticles ();
void				CL_BlasterTrail (const vec3_t start, const vec3_t end, particleSource_t *particle);
void				CL_GrenadeTrail (const vec3_t start, const vec3_t end, particleSource_t *particle);
void				CL_RocketTrail (const vec3_t start, const vec3_t end, particleSource_t *particle, particleSource_t *particle2);
void				CL_RailTrail (const vec3_t start, const vec3_t end, particleSource_t *particle, particleSource_t *particle2);
void				CL_BubbleTrail (const vec3_t start, const vec3_t end, float dist, float radius, particleSource_t *particle);
void				CL_FlagTrail (const vec3_t start, const vec3_t end, particleSource_t *particle);
void				CL_TracerTrail (const vec3_t start, const vec3_t end, particleSource_t *particle);
void				CL_BlasterParticles (const vec3_t org, const vec3_t dir, particleSource_t *particle, particleSource_t *particle2);
void				CL_BulletParticles (const vec3_t org, const vec3_t dir, particleSource_t *particle, particleSource_t *particle2);
void				CL_SmokePuffParticles (const vec3_t org, float radius, int count, particleSource_t *particle);
void				CL_BubbleParticles (const vec3_t org, int count, float magnitude, particleSource_t *particle);

void				CL_ClearLightStyles ();
void				CL_RunLightStyles ();
void				CL_AddLightStyles ();
void				CL_SetLightStyle (int style);

/*
 ==============================================================================

    CL_TEMPENTS.CPP

 ==============================================================================
*/

void				CL_AddBeams ();
void				CL_ClearBeams ();

void				CL_ParseTempEntity (sizebuf_t *msg);

/*
 ==============================================================================

    CL_ENTITIES.CPP

 ==============================================================================
*/

void				CL_AddPacketEntities ();
void				CL_AddViewWeapon ();

/*
 ==============================================================================

    CL_VIEW.CPP

 ==============================================================================
*/

void				CL_TestModel_f ();
void				CL_TestDecal_f ();

void				CL_RenderActiveFrame ();

/*
 ==============================================================================

    CL_DRAW.CPP

 ==============================================================================
*/

enum textAlignFlags {
	TAF_LEFT,
	TAF_CENTER,
	TAF_RIGHT
};

/*
 ==============================================================================

    CL_CONSOLE.CPP

 ==============================================================================
*/

void				Con_CharEvent (int ch);
void				Con_KeyEvent (int key, bool down);

void				Con_Close ();
void				Con_Toggle ();
void				Con_Run ();
void				Con_Draw ();

void				Con_Init ();
void				Con_Shutdown ();

/*
 ==============================================================================

    CL_MAIN.CPP

 ==============================================================================
*/

extern cvar_t				*cl_hand;

extern cvar_t				*cl_showPredictionMiss;

extern cvar_t				*cl_smallFont;
extern cvar_t				*cl_largeFont;

extern cvar_t				*cl_crosshairSize;
extern cvar_t				*cl_crosshairX;
extern cvar_t				*cl_crosshairY;
extern cvar_t				*cl_crosshairColor;
extern cvar_t				*cl_crosshairAlpha;

extern cvar_t				*cl_drawLogo;
extern cvar_t				*cl_drawCrosshair;
extern cvar_t				*cl_crosshairNames;
extern cvar_t				*cl_drawFPS;
extern cvar_t				*cl_showMaterial;

extern cvar_t				*cl_predict;

void				CL_UpdateScreen ();


#else
FILE_WARNING
#endif   // __CL_LOCAL_H__